<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
        <script>
                //1. 对象转字符串  JSON.stringify()
                var car={
                    name:"奔驰",
                    color:"红色",
                    price:111
                }
             
                var carstr=JSON.stringify(car)
                console.log(carstr)

                var arr=[{name:"赵四",age:28},{name:"小沈阳",age:18},{name:"肖战",age:29}]

                var arrstr=JSON.stringify(arr)
                console.log(arrstr)
                // 把对象或数组 转换成json字符串后 存入localStroage
                // localStorage 中存储 对象和数组 先用JSON.stringify() 转换后 存储数据
                localStorage.stararr=arrstr;
                localStorage.cararr=carstr;
        </script>
</body>
</html>